package com.bsiprosoft.ejerciciosandoidproject;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.widget.TextView;

/**
 * Created by pbastidas on 12/16/13.
 */
public class EjemploSingleTouch extends Activity implements View.OnTouchListener {

    TextView textView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        textView = new TextView(this);
        textView.setText("Toca la pantalla (un dedo) y veras... :D");
        textView.setOnTouchListener(this);

        setContentView(textView);
    }

    @Override
    public boolean onTouch(View view, MotionEvent motionEvent) {
        StringBuilder accion = new StringBuilder();

        // Defino que evento se presentó
        switch (motionEvent.getAction()) {
            case MotionEvent.ACTION_DOWN:
                accion.append("DOWN, ");
                break;
            case MotionEvent.ACTION_UP:
                accion.append("UP, ");
                break;
            case MotionEvent.ACTION_CANCEL:
                accion.append("CANCEL, ");
                break;
            case MotionEvent.ACTION_MOVE:
                accion.append("MOVE, ");
                break;
        }

        // Obtengo la posición del evento en sus ejes
        accion.append(motionEvent.getX());
        accion.append(", ");
        accion.append(motionEvent.getY());

        String evento = accion.toString();

        Log.d(this.getLocalClassName(), evento);

        textView.setText(evento);

        return true;
    }
}
